package com.itheima.controller;


import com.itheima.domain.Result;
import com.itheima.domain.pojo.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {


    //AAAAA
    @Autowired
    private DeptService deptService;
    @Autowired
    private DeptMapper deptMapper;

    @GetMapping
    public Result list(){
        log.info("查询所有部门信息");
        List<Dept> depts =deptService.findAll();
        return Result.success(depts);
    }


    @DeleteMapping
    public Result deleteById(@RequestParam("id") Integer id){
        deptService.deleteById(id);
        return Result.success();
    }

    /**
     * 添加部门
     * @param dept
     * @return
     */
    @PostMapping
    public Result InsertDept(@RequestBody Dept dept){
        deptService.insertDept(dept);
        return Result.success();
    }

    /**
     * 根据id回显部门信息
     *
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Dept dept=deptService.getById(id);
        return Result.success(dept);
    }

    /**
     *
     * 根据id修改部门信息
     */
    @PutMapping
    public Result updateById(@RequestBody Dept dept){
        deptService.upadteDept(dept);
        return Result.success();
    }


}
